package com.wawayaya.bookreader.worddict;

import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.graphics.Typeface;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.cache.BitmapCache;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.NetworkImageView;
import com.wawayaya.AppContext;
import com.wawayaya.api.ApiRequestParams;
import com.wawayaya.api.ApiResponseData;
import com.wawayaya.api.interf.ApiResponseJsonListener;
import com.wawayaya.api.remote.ApiConstans;
import com.wawayaya.api.remote.ApiWawayaya;
import com.wawayaya.bookreader.DefaultSettings;
import com.wawayaya.bookreader.Imutualaction;
import com.wawayaya.bookreader.TouchMoveLinearLayout;
import com.wawayaya.bookreader.bean.EnDictData;
import com.wawayaya.bookreader.bean.IntDouble;
import com.wawayaya.bookreader.bean.ShortPoint;
import com.wawayaya.bookreader.bean.StringDouble;
import com.wawayaya.bookreader.bean.StrokeRecord;
import com.wawayaya.bookreader.jni.PinyinConvert;
import com.wawayaya.bookreader.stroke.StrokeEventInterface;
import com.wawayaya.bookreader.stroke.StrokeRecordLoader;
import com.wawayaya.bookreader.stroke.StrokeView;
import com.wawayaya.bookreader.stroke.StrokeWave;
import com.wawayaya.bookreader.stroke.provider.StrokeProvider;
import com.wawayaya.db.bookreader.DictionaryENDB;
import com.wawayaya.db.bookreader.DictionaryCNDB;
import com.wawayaya.util.FileUtil;
import com.wawayaya.util.PreferenceUtils;
import com.wawayaya.util.TDevice;
import com.wawayaya.util.TLog;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Vector;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import wawayaya.kids_iread.R;


public class NewViewWordDictdesc extends TouchMoveLinearLayout implements StrokeEventInterface, StrokeView.QueryStroke{
	
	private final static int MSG_DICTTEXTOK = 0;
	private final static int MSG_DICTTEXTERROR = 1;
	private final static int MSG_DICTDIMAGEERROR = 2;
    private final static int MSG_DICTTEXTOK_EN = 3;
	private final static String MSG_BUNDLEKEY_WORDDATA = "worddata";
		
	private final static String jsondict_key_word = "word";
	private final static String jsondict_key_dicts = "dicts";
    private final static String jsondict_key_type = "type";
	private final static String jsondict_key_name = "name";
	private final static String jsondict_key_items = "items";
	private final static String jsondict_key_pin_yin = "pin_yin";
	private final static String jsondict_key_jie_shi = "jie_shi";
	private final static String jsondict_key_str = "str";
	private final static String jsondict_key_duan_yu = "duan_yu";
	private final static String jsondict_key_li_ju = "li_ju";
	private final static String jsondict_key_chs = "chs";
	private final static String jsondict_key_eng = "eng";
	private final static String jsondict_key_peitu = "pei_tu";
	private final static String jsondict_key_fanyic = "fan_yi_ci";
	private final static String jsondict_key_duyins = "duyin";
    private final static String jsondict_key_yinbiao = "yin_biao";
    private final static String jsondict_key_cixing = "ci_xing";
    private final static String jsondict_key_fushu = "fu_shu";
    private final static String jsondict_key_cx = "cx";
    private final static String jsondict_key_js = "js";
    private final static String jsondict_key_lj = "lj";
    private final static String jsondict_key_lj_js = "lj_js";


	public final static int INVALIDVIEWID = -1;
	//private LinearLayout m_llheaddecoration = null;
	//rivate LinearLayout m_llintervalholder = null;
    private ProgressBar m_pbdictdescwait = null;
	private ScrollView m_svworddictdata = null;
    //private ViewWordDictText m_tvbaseword = null;
    private LinearLayout m_keywordLayout = null;
    private ImageView m_bnwordsound = null;
    //private ViewWordDictPinyin m_vwdp_pinyin = null;
    private TextView m_vwdp_pinyin = null;
    private NetworkImageView m_ivwordimage = null;
    private WebView m_wvdictdescitems = null;

    private ImageButton mSwitchButton = null;
    private RelativeLayout mSwitchLayout = null;

	//private float m_fratiox = 1.0f;
	//private float m_fratioy = 1.0f;
	private int m_iworkregionYmargins = 0;
	//private devicescreenbasicinfo m_dsi = null;
	private Imutualaction m_callback = null;
	//private boolean m_bisbooklandscape = false;
	
	private Context m_ct = null;
	//private Bitmap m_bmpdictimgfailed = null;
	//private Bitmap m_bmpdictimgwait = null;
	private RequestQueue m_rqvolleyref = null;
	private BitmapCache m_bmpcache = null;
	private ImageLoader m_loader = null;
	private JsonObjectRequest m_rqworddictdata = null;
	private TrdGetWordDictdescSound m_trdworddictsound = null;
	private int m_iviewId = -1;
	private String m_sdictimgprefixurl = null;
	private String m_sdictsoundprefixurl = null;
	private MediaPlayer m_mpworddict = null;
	private StringDouble[] m_sdsoundspathes = null;
	private int m_isoundspathesidx = 0;
	private Timer m_tmdictsound = null;
	private TimerTask m_ttdictsound = null;
	private AtomicBoolean m_bstopsound = new AtomicBoolean(false);

    private RelativeLayout mStrokeLayout;
    private ImageView mStrokeDownBtn;
    private AtomicInteger mStrokeShow = new AtomicInteger(0);
    private String mStrokeWord = "";
    private Animation mStrokeInAnim;
    private Animation mStrokeOutAnim;
    private StrokeWave mStrokeWave = null;
    private StrokeView  mStrokeView;
    private boolean   mEnglishPage =false;
    private MediaPlayer mStrokePlayer = null;
    private String[] mStrokeNameTable = {"点", "横", "横钩", "横撇","横撇弯钩", "横撇折折钩", "横折", "横折钩", "横折提","横折弯",
    "横折弯钩","横折斜钩", "横折折","横折折撇","横折折折钩","捺","撇","撇点","撇折","竖","竖钩","竖提","竖弯","竖弯钩",
    "竖折","竖折撇","竖折竖","竖折折钩","竖折折撇","竖折折折","提","弯钩","卧钩","斜钩","左弯钩"} ;

    private DictionaryCNDB mDb;
    private DictionaryENDB mEnDb;
    //private PinyinConvert mPinyinConvert;

    private  final static  int   DICT_MODE_CNCN = 1;
    private  final static  int   DICT_MODE_CNEN = 2;
    private  int                 mDictMode = DICT_MODE_CNCN;
    private  WordDictdescData    mCurWdd;
    private  EnWordDictDescData    mCurEnWdd;
	
	public NewViewWordDictdesc(Context context) {
		super(context);
		init(context);
	}

	public NewViewWordDictdesc(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}
	public NewViewWordDictdesc(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init(context);
	}


    public void setmEnglishPage(boolean englishPage) {
        if (englishPage == mEnglishPage) return;

        mEnglishPage = englishPage;
        Typeface tfpintyin;

        if (mEnglishPage) {
            tfpintyin = Typeface.createFromAsset(m_ct.getAssets(), "HANSPHON.ttf");
        }  else {
            tfpintyin = Typeface.createFromAsset(m_ct.getAssets(), "HansPhonic80_xbxszd.ttf");
        }
        m_vwdp_pinyin.setTypeface(tfpintyin);

        if (mEnglishPage) {
            mSwitchLayout = (RelativeLayout)findViewById(R.id.switch_btn_layout);
            mSwitchLayout.setVisibility(View.GONE);

        } else {

            mSwitchButton = (ImageButton) findViewById(R.id.switch_btn);

            int defaultDictMode = DICT_MODE_CNEN;
            if (TDevice.isZh(m_ct)) {
                defaultDictMode = DICT_MODE_CNCN;
            }
            mDictMode = PreferenceUtils.getCurDictMode(m_ct, defaultDictMode);
            if (mDictMode == DICT_MODE_CNEN) {
                mSwitchButton.setImageResource(R.drawable.btn_worddict_cnen);
            } else {
                mSwitchButton.setImageResource(R.drawable.btn_worddict_cncn);
            }
            mSwitchButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    m_svworddictdata.scrollTo(0, 0);
                    if (mDictMode == DICT_MODE_CNEN) {
                        mDictMode = DICT_MODE_CNCN;
                        mSwitchButton.setImageResource(R.drawable.btn_worddict_cncn);
                        PreferenceUtils.setCurDictMode(m_ct, DICT_MODE_CNCN);
                        if (mCurWdd != null) {
                            listworddictdesc(mCurWdd);
                        }
                    } else {
                        mDictMode = DICT_MODE_CNEN;
                        mSwitchButton.setImageResource(R.drawable.btn_worddict_cnen);
                        PreferenceUtils.setCurDictMode(m_ct, DICT_MODE_CNEN);
                        if (mCurWdd != null) {
                            listworddictdesc(mCurWdd);
                        }
                    }
                }
            });
        }

    }
    public void findviews(/*devicescreenbasicinfo dsi, *//*float fratiox, float ratioy, boolean bisbooklandscape,*/
			/*Bitmap bmpdictimgfailed,*/ /*Bitmap bmpdictimgwait,*/ /*Bitmap bmpwordsound[],*/
			/*IntDouble idusize,*/
			String sdictimgprefixurl, String sdictsoundprefixurl,
			Imutualaction callback, float sceendensity,boolean  englishPage) {

       // mPinyinConvert = new PinyinConvert();
		//m_dsi = dsi;
		//m_fratiox = fratiox;
		//m_fratioy = ratioy;
        mEnglishPage = englishPage;
		m_callback = callback;
		//m_bisbooklandscape = bisbooklandscape;
	    
		int iheaddcorationheight = 0;
        /*
		m_llheaddecoration = (LinearLayout)findViewById(R.id.ll_headdecoration);
		LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)m_llheaddecoration.getLayoutParams();
	    if(null != lp) {
	    	if(m_bisbooklandscape) {
		    	lp.height = idusize.m_ival1 * DefaultSettings.WORDDICTDESC_H_WORKREGION_HEADDCORATION_HEIGHT / DefaultSettings.WORDDICTDESC_H_WORKREGION_HEADDCORATION_WIDTH;
		    	m_llheaddecoration.setBackgroundResource(R.drawable.worddictframe_h);
	    	}
	    	else{	
		    	lp.height = idusize.m_ival1 * DefaultSettings.WORDDICTDESC_WORKREGION_HEADDCORATION_HEIGHT / DefaultSettings.WORDDICTDESC_WORKREGION_HEADDCORATION_WIDTH;
		    	m_llheaddecoration.setBackgroundResource(R.drawable.worddictframe);
	    	}
	    	iheaddcorationheight = lp.height;
	    	m_llheaddecoration.setLayoutParams(lp);
	    }*/

        LinearLayout.LayoutParams lp;
/*		m_llintervalholder = (LinearLayout)findViewById(R.id.ll_intervalholder);
	    lp = (LinearLayout.LayoutParams)m_llintervalholder.getLayoutParams();
	    if(null != lp) {
	    	lp.height = getscaledsize(DefaultSettings.BOOKTOPMENUBAR_TOBOOKSHELFSIZE / 5);
	    	m_llintervalholder.setLayoutParams(lp);
	    }
		*/
		m_svworddictdata = (ScrollView)findViewById(R.id.sv_contentitems);
/*		lp = (LinearLayout.LayoutParams)m_svworddictdata.getLayoutParams();
	    if(null != lp) {
	    	lp.width = idusize.m_ival1 - 2 * 30;
	    	lp.leftMargin = (int)(25 * m_dsi.m_fscreendensity);
	    	m_svworddictdata.setLayoutParams(lp);
	    }*/
	    m_pbdictdescwait = (ProgressBar)findViewById(R.id.pb_waitdict);
	    
		//m_tvbaseword = (ViewWordDictText)findViewById(R.id.vwd_word);
	    //m_tvbaseword.setTextSize(Math.min(DefaultSettings.WORDDICTDESC_WORKREGION_BASEWORD_FONTSIZEMAX, getscaledfontsize(DefaultSettings.WORDDICTDESC_WORKREGION_BASEWORD_FONTSIZE)));
    	//m_tvbaseword.setviewwidthrestriction(idusize.m_ival1 - 20, idusize.m_ival1 - 20);
        m_keywordLayout = (LinearLayout)findViewById(R.id.keyword_layout);

	    m_vwdp_pinyin = (TextView)findViewById(R.id.vwdp_wpinyin);
        Typeface tfpintyin;
        if (mEnglishPage) {
            tfpintyin = Typeface.createFromAsset(m_ct.getAssets(), "HANSPHON.ttf");
        }  else {
            tfpintyin = Typeface.createFromAsset(m_ct.getAssets(), "HansPhonic80_xbxszd.ttf");
        }
        m_vwdp_pinyin.setTypeface(tfpintyin);
	/*    m_vwdp_pinyin.setTextSize(Math.min(DefaultSettings.WORDDICTDESC_WORKREGION_PINYIN_FONTSIZEMAX,
	    		getscaledfontsize(DefaultSettings.WORDDICTDESC_WORKREGION_PINYIN_FONTSIZE)));*/
	    //m_vwdp_pinyin.setviewwidthrestriction(idusize.m_ival1 - (int)(30 * m_dsi.m_fscreendensity), idusize.m_ival1 - (int)(30 * m_dsi.m_fscreendensity));
	    
	    m_wvdictdescitems = (WebView)findViewById(R.id.wv_contentitems);
	    
	    //m_bmpdictimgfailed = bmpdictimgfailed;
	   // m_bmpdictimgwait = bmpdictimgwait;
	    m_ivwordimage = (NetworkImageView)findViewById(R.id.iv_worddictimage);
/*	    LinearLayout.LayoutParams llp = (LinearLayout.LayoutParams)m_ivwordimage.getLayoutParams();
	    if(null != llp) {
	    	llp.height = (idusize.m_ival2 - iheaddcorationheight) / 3;
	    	m_ivwordimage.setLayoutParams(llp);
	    }
	    m_ivwordimage.setImageBitmap(m_bmpdictimgwait);*/
	    m_ivwordimage.setVisibility(View.GONE);
	    m_sdictimgprefixurl = sdictimgprefixurl;
	    m_sdictsoundprefixurl = sdictsoundprefixurl;

        mStrokeLayout = (RelativeLayout)findViewById(R.id.stroke_layout);
        //mStrokeView = (OldStrokeView)findViewById(R.id.strokeview);
        mStrokeView = (StrokeView)findViewById(R.id.strokeview);
        mStrokeView.setscreendensity(sceendensity);
        mStrokeView.SetLineColor( 0xffa0a0a0);
        mStrokeView.mQueryCallback = this;
        mStrokeView.mStrokeEvent = this;
        mStrokeView.setFillStyle(2);
       // mStrokeViewNew.m_bShowStroke = true;
        mStrokeView.setGridType(2);
        mStrokeView.setStrokeColor(0);
        mStrokeView.setFillBuShouColor(Color.BLACK);
        mStrokeView.setFillBuYuColor(Color.BLACK);
       // mStrokeViewNew.SetText("1", str);
        mStrokeView.setReadOnly(true);
        mStrokeView.setSpeedParam(5);
        mStrokeView.setMaximumFillCount(500);
        mStrokeView.setZhuBiMode(false);
        mStrokeView.m_bShowStroke = false;
        mStrokeView.m_bShowOutline = false;
        mStrokeView.m_bShowSkeleton = false;
        mStrokeView.showStartPoint(true);
        mStrokeView.enableSmoothContour(true);


        mStrokeDownBtn = (ImageView)findViewById(R.id.hidestrokeview);

        //mStrokeData = new StrokeData((Activity)m_ct);
        mStrokeInAnim = AnimationUtils.loadAnimation(m_ct, R.anim.stroke_in);
        mStrokeInAnim.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                mStrokeLayout.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                if (mStrokeShow.get() == 1) {
                    mStrokeShow.incrementAndGet();
                    setStrokeWord(mStrokeWord);
                }
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });



        mStrokeOutAnim = AnimationUtils.loadAnimation(m_ct, R.anim.stroke_out);
        mStrokeOutAnim.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                if (mStrokeShow.get() == -1) {
                    mStrokeView.continueNextStroke();
                    mStrokeView.stopStrokeAnimation();
                    mStrokeView.ReSet();
                    if (mStrokeWave != null) {
                        mStrokeWave.closeWave();
                    }
                }
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                if (mStrokeShow.get() == -1) {
                    mStrokeShow.incrementAndGet();
                    mStrokeLayout.setVisibility(View.GONE);
                    //mStrokeView.clear();
                    //mStrokeData.clearOldPoints();
                    mStrokeWord = "";
                }
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });

   /*     mStrokeView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (mStrokeShow.get() == 2) {
                    mStrokeView.pause();
                    mStrokeView.resume();
                }
            }
        });*/
        mStrokeDownBtn.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                if (mStrokeShow.get() < 2) {
                    return;
                } else {


                    mStrokeShow.set(-1);
                    mStrokeLayout.startAnimation(mStrokeOutAnim);
                    //mStrokeLayout.setAnimation(mStrokeOutAnim);
                    //mStrokeOutAnim.startNow();
                }

            }
        });

        if (mEnglishPage) {
            mSwitchLayout = (RelativeLayout)findViewById(R.id.switch_btn_layout);
            mSwitchLayout.setVisibility(View.GONE);

        } else {

            mSwitchButton = (ImageButton) findViewById(R.id.switch_btn);

            int defaultDictMode = DICT_MODE_CNEN;
            if (TDevice.isZh(m_ct)) {
                defaultDictMode = DICT_MODE_CNCN;
            }
            mDictMode = PreferenceUtils.getCurDictMode(m_ct, defaultDictMode);
            if (mDictMode == DICT_MODE_CNEN) {
                mSwitchButton.setImageResource(R.drawable.btn_worddict_cnen);
            } else {
                mSwitchButton.setImageResource(R.drawable.btn_worddict_cncn);
            }
            mSwitchButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    m_svworddictdata.scrollTo(0, 0);
                    if (mDictMode == DICT_MODE_CNEN) {
                        mDictMode = DICT_MODE_CNCN;
                        mSwitchButton.setImageResource(R.drawable.btn_worddict_cncn);
                        PreferenceUtils.setCurDictMode(m_ct, DICT_MODE_CNCN);
                        if (mCurWdd != null) {
                            listworddictdesc(mCurWdd);
                        }
                    } else {
                        mDictMode = DICT_MODE_CNEN;
                        mSwitchButton.setImageResource(R.drawable.btn_worddict_cnen);
                        PreferenceUtils.setCurDictMode(m_ct, DICT_MODE_CNEN);
                        if (mCurWdd != null) {
                            listworddictdesc(mCurWdd);
                        }
                    }
                }
            });

        }



	}
	
	public void stopgetworddictionarydata() {
		setTag(NewViewWordDictdesc.INVALIDVIEWID);
		if(null != m_rqworddictdata){
			m_rqworddictdata.cancel();
		}
		m_rqworddictdata = null;
		if(null != m_rqvolleyref) {
			m_rqvolleyref.cancelAll();
		}
	}
	
	public void clearviews() {
		if(null != m_trdworddictsound) {
			m_trdworddictsound.topause();
            try {
                m_trdworddictsound.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            m_trdworddictsound = null;
		}
		closeworddictsoundplay();
		m_isoundspathesidx = 0;
		if(null != m_sdsoundspathes) {
			for(int i = 0; i < m_sdsoundspathes.length; i++) {
				m_sdsoundspathes[i] = null;
			}
			m_sdsoundspathes = null;
		}
		if(null != m_bnwordsound){
			m_bnwordsound.setVisibility(View.GONE);
		}
		if(null != m_ivwordimage){
			m_ivwordimage.setImageBitmap(null);
			//m_ivwordimage.setVisibility(View.GONE);
		}
		if(null != m_bnwordsound) {
			m_bnwordsound.setBackgroundDrawable(null);
			m_bnwordsound.setVisibility(View.GONE);
		}
/*	   	if(null != m_tvbaseword) {
	   		m_tvbaseword.setText(null);
	   	}*/
        if (null != m_keywordLayout) {
            m_keywordLayout.removeAllViews();
        }
	    if(null != m_vwdp_pinyin) {
	    	m_vwdp_pinyin.setText(null);
	    }
		if(null != m_wvdictdescitems) {
			m_wvdictdescitems.loadUrl("");
    }
		if(null != m_pbdictdescwait){
			m_pbdictdescwait.setVisibility(View.GONE);
		}

        //mStrokeView.pause();
        mStrokeShow.set(0);
        mStrokeLayout.setVisibility(View.GONE);

        mStrokeView.continueNextStroke();
        mStrokeView.stopStrokeAnimation();
        mStrokeView.ReSet();
        if (mStrokeWave != null) {
            mStrokeWave.closeWave();
        }


        //mStrokeView.clear();
        //mStrokeData.clearOldPoints();
        mStrokeWord="";

		
        //cleartempdostrokemp4();

	}
	
	public void showworddictionarydata(RequestQueue rqvolley,
			int ibookid,
			int ibooknetid, 
			String sdictword, String sdictpinyin,
			int iviewId,
			String spf, int osver, String sappver){
		m_iviewId = iviewId;
		if(null == rqvolley) {
			return;
		}
		Integer ii = (Integer)getTag();
		if(null == ii || ii.intValue() != iviewId){
			TLog.log("MyLog --------- NewViewWordDictdesc : showworddictionarydata : "
                    + (null == ii ? "null error" : "") + " or " + ii.intValue() + " != " + iviewId);
			return;
		}
		m_rqvolleyref = rqvolley;
		resetviews(sdictword, sdictpinyin,false);
		WordDictdescData wdd = newreadtextdescfromdatabase(ibookid, ibooknetid, m_iviewId, sdictword, sdictpinyin);
        mCurWdd = wdd;
		if(null != wdd && null != m_hshowworddictdata) {
			Message msg = new Message();
			msg.what = MSG_DICTTEXTOK;
			msg.arg1 = 0;
			Bundle bd = new Bundle();
			bd.putParcelable(MSG_BUNDLEKEY_WORDDATA, wdd);
			msg.setData(bd);
			m_hshowworddictdata.sendMessage(msg);
			return;
		}
        getWorddictInfoByRequestManager(ibookid, ibooknetid, m_iviewId, sdictword, sdictpinyin);
	}

    public void showEnWordDictionaryData(RequestQueue rqvolley,
                                       int ibookid,
                                       int ibooknetid,
                                       EnDictData data,
                                       int iviewId,
                                       String spf, int osver, String sappver){
        m_iviewId = iviewId;
        if(null == rqvolley) {
            return;
        }
        Integer ii = (Integer)getTag();
        if(null == ii || ii.intValue() != iviewId){
            TLog.log("MyLog --------- NewViewWordDictdesc : showEnWordDictionaryData : "
                    + (null == ii ? "null error" : "") + " or " + ii.intValue() + " != " + iviewId);
            return;
        }
        m_rqvolleyref = rqvolley;
        resetviews(data.mBaseData.getdictword() , null, true);
        EnWordDictDescData wdd = readEnWordDescFromDatabase(ibookid, ibooknetid, m_iviewId, data.mJansonPhrase,
                data.mPhraseIndex, data.mBaseData.getdictword(),  false);
        mCurEnWdd = wdd;
        if(null != wdd && null != m_hshowworddictdata) {
            Message msg = new Message();
            msg.what = MSG_DICTTEXTOK_EN;
            msg.arg1 = 0;
            Bundle bd = new Bundle();
            bd.putParcelable(MSG_BUNDLEKEY_WORDDATA, wdd);
            msg.setData(bd);
            m_hshowworddictdata.sendMessage(msg);
            return;
        }

       getEnWorddictInfoByRequestManager(ibookid, ibooknetid, m_iviewId, data.mJansonPhrase, data.mPhraseIndex,
               data.mBaseData.getdictword());
    }


    public void informworddictsoundfileok(int ibookid, int inetid,int  iviewid, String sbaseword, StringDouble[] sdSounds){
		informworddictsoundfileok.sendEmptyMessage(0);
		//startworddictsoundplay(sdSounds);
	}
	
	private Handler informworddictsoundfileok = new Handler(){
		@Override
		public void handleMessage(Message msg) {
            m_bnwordsound.setBackgroundResource(R.drawable.dictsound1);
			m_bnwordsound.setVisibility(View.VISIBLE);
		}
	};
	
	private void resetviews(String sbaseword, String spinyin, boolean englishpage){
        if (mStrokeShow.get() > 0) {
            mStrokeShow.set(-1);
            mStrokeLayout.startAnimation(mStrokeOutAnim);
        }


		if(null != m_trdworddictsound) {
			m_trdworddictsound.pausefinal();
            try {
                m_trdworddictsound.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
			m_trdworddictsound = null;
		}
		closeworddictsoundplay();
		m_isoundspathesidx = 0;
		if(null != m_sdsoundspathes) {
			for(int i = 0; i < m_sdsoundspathes.length; i++) {
				m_sdsoundspathes[i] = null;
			}
			m_sdsoundspathes = null;
		}
		int ipinyinleftmargin = 0;
		if(!TextUtils.isEmpty(sbaseword)){
/*			m_tvbaseword.setbasewordtext(sbaseword, true);
			LinearLayout.LayoutParams llp = (LinearLayout.LayoutParams)m_tvbaseword.getLayoutParams();
			if(null != llp) {
				llp.leftMargin = m_tvbaseword.getviewwidth() / m_tvbaseword.length();
				llp.width = m_tvbaseword.getviewwidth();
				llp.height = m_tvbaseword.getviewHeight();
				llp.bottomMargin = m_iworkregionYmargins;
				m_tvbaseword.setLayoutParams(llp);
				ipinyinleftmargin = llp.leftMargin;
			}	*/
/*            m_keywordLayout.removeAllViews();
            int char_num = sbaseword.length();
            for (int i = 0; i < char_num; i++) {
                TextView wordview = new TextView(m_ct);
                wordview.setText(sbaseword.substring(i, i+1));
                wordview.setTextColor(m_ct.getResources().getColor(R.color.worddict_keyword_textcolor));
                wordview.setTextSize(m_ct.getResources().getDimension(R.dimen.worddict_keyword_fontsize));
                LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
                m_keywordLayout.addView(wordview, lp);
            }*/
            setKeyWord(sbaseword);

		} else {
            setKeyWord(null);
        }
		if(!TextUtils.isEmpty(spinyin)){
/*			m_vwdp_pinyin.setindicatedtext(utils.makepinyinforonlinequery(spinyin), true);
			LinearLayout.LayoutParams llp = (LinearLayout.LayoutParams)m_vwdp_pinyin.getLayoutParams();
			if(null != llp) {
				llp.leftMargin = ipinyinleftmargin;
				llp.bottomMargin = m_iworkregionYmargins;
				llp.width = m_vwdp_pinyin.getviewwidth();
				llp.height = m_vwdp_pinyin.getviewHeight();
				m_vwdp_pinyin.setLayoutParams(llp);
			}*/
            //m_vwdp_pinyin.setText(pinyin.convertpinyin(utils.makepinyinforonlinequery(spinyin)));
            //m_vwdp_pinyin.setText(null);
		} else {
            m_vwdp_pinyin.setText(null);
        }
		if(null != m_pbdictdescwait){
			m_pbdictdescwait.setVisibility(View.VISIBLE);
		}
		
		m_svworddictdata.setVisibility(View.GONE);
		if(null != m_bnwordsound){
			m_bnwordsound.setVisibility(View.GONE);
		}
		if(null != m_ivwordimage){
			//m_ivwordimage.setImageBitmap(m_bmpdictimgwait);
            //m_ivwordimage.setBackgroundResource(R.drawable.dictimagewait);
            m_ivwordimage.setImageResource(R.drawable.dictimagewait);
			//m_ivwordimage.setVisibility(View.GONE);
		}
		if(null != m_bnwordsound) {
			m_bnwordsound.setBackgroundResource(0);
			m_bnwordsound.setVisibility(View.GONE);
		}
		if(null != m_wvdictdescitems) {
			m_wvdictdescitems.loadUrl("");
			m_wvdictdescitems.setVisibility(View.GONE);
		}		
        //cleartempdostrokemp4();
	}
	
	private void init(Context context) {
		m_ct = context;
/*		this.setOnTouchListener(new OnTouchListener(){
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				return true;
			}
		});*/
	}

	private void adjustwordsoundimageposition(/*LinearLayout.LayoutParams llpbaseword,*/ WordDictdescData wdd){
		if(null == wdd || null == wdd.m_ssduyin || wdd.m_ssduyin.length <= 0) {
			return;
		}
		if(null == m_bnwordsound) {
            m_bnwordsound = (ImageView)findViewById(R.id.bn_wordsound);
        }
		m_bnwordsound.setVisibility(View.GONE);
/*		LinearLayout.LayoutParams lpbn = (LinearLayout.LayoutParams)m_bnwordsound.getLayoutParams();
		if(null != lpbn && null != llpbaseword){
				lpbn.width = llpbaseword.height * 2 / 3;
				lpbn.height = lpbn.width;
				lpbn.topMargin = llpbaseword.topMargin;// + llpbaseword.height / 6 + 1;
				lpbn.leftMargin = llpbaseword.height / 2;
				m_bnwordsound.setLayoutParams(lpbn);
		}*/
		
		final StringDouble spathes[] = new StringDouble[wdd.m_ssduyin.length];
		for(int i = 0; i < wdd.m_ssduyin.length; i++) {
			try{
				spathes[i] = new StringDouble(m_sdictsoundprefixurl + File.separator + wdd.m_ssduyin[i], convetsoundurltosdcardpath(wdd.m_ssduyin[i]));
			}catch(Exception e){
				return;
			}
		}
		m_sdsoundspathes = spathes;
		m_bnwordsound.setOnClickListener(new Button.OnClickListener(){
			@Override
			public void onClick(View v) {
				startworddictsoundplay(spathes);
			}
		});
		for(int i = 0; i < spathes.length; i++) {
			try{
                File soundfile = new File(spathes[i].m_sVal2);
				if(!soundfile.exists()){
					throw new Exception("No such file");
				} else if (soundfile.length() <= 0) {
                    TLog.log("Sound file length is 0 " + spathes[i].m_sVal2);
                    soundfile.delete();
                    throw new Exception("No such file");
                }
			}catch(Exception e){
				if(null == m_trdworddictsound) {
					m_trdworddictsound = new TrdGetWordDictdescSound(wdd.m_ibookid, wdd.m_inetid, wdd.m_iviewId, wdd.m_sbaseword, spathes, m_callback);
					m_trdworddictsound.start();
				}
				return;
			}
		}
        m_bnwordsound.setBackgroundResource(R.drawable.dictsound1);
		m_bnwordsound.setVisibility(View.VISIBLE);
		//startworddictsoundplay(m_sdsoundspathes);
	}



    private void adjustEnWordSoundImagePosition(EnWordDictDescData wdd){
        if(null == wdd || null == wdd.m_ssduyin || wdd.m_ssduyin.length <= 0) {
            return;
        }
        if(null == m_bnwordsound) {
            m_bnwordsound = (ImageView)findViewById(R.id.bn_wordsound);
        }
        m_bnwordsound.setVisibility(View.GONE);
/*		LinearLayout.LayoutParams lpbn = (LinearLayout.LayoutParams)m_bnwordsound.getLayoutParams();
		if(null != lpbn && null != llpbaseword){
				lpbn.width = llpbaseword.height * 2 / 3;
				lpbn.height = lpbn.width;
				lpbn.topMargin = llpbaseword.topMargin;// + llpbaseword.height / 6 + 1;
				lpbn.leftMargin = llpbaseword.height / 2;
				m_bnwordsound.setLayoutParams(lpbn);
		}*/

        final StringDouble spathes[] = new StringDouble[wdd.m_ssduyin.length];
        for(int i = 0; i < wdd.m_ssduyin.length; i++) {
            try{
                spathes[i] = new StringDouble(m_sdictsoundprefixurl + File.separator + wdd.m_ssduyin[i], convetsoundurltosdcardpath(wdd.m_ssduyin[i]));
            }catch(Exception e){
                return;
            }
        }
        m_sdsoundspathes = spathes;
        m_bnwordsound.setOnClickListener(new Button.OnClickListener(){
            @Override
            public void onClick(View v) {
                startworddictsoundplay(spathes);
            }
        });
        for(int i = 0; i < spathes.length; i++) {
            try{
                File soundfile = new File(spathes[i].m_sVal2);
                if(!soundfile.exists()){
                    throw new Exception("No such file");
                } else if (soundfile.length() <= 0) {
                    TLog.log("Sound file length is 0 " + spathes[i].m_sVal2);
                    soundfile.delete();
                    throw new Exception("No such file");
                }
            }catch(Exception e){
                if(null == m_trdworddictsound) {
                    m_trdworddictsound = new TrdGetWordDictdescSound(wdd.m_ibookid, wdd.m_inetid, wdd.m_iviewId, wdd.mBaseWord, spathes, m_callback);
                    m_trdworddictsound.start();
                }
                return;
            }
        }
        m_bnwordsound.setBackgroundResource(R.drawable.dictsound1);
        m_bnwordsound.setVisibility(View.VISIBLE);
        //startworddictsoundplay(m_sdsoundspathes);
    }
	
	private Handler m_hshowworddictdata = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			switch(msg.what){
			case MSG_DICTTEXTOK:
				Bundle bd = msg.getData();
				if(null != bd){
					WordDictdescData wdd = bd.getParcelable(MSG_BUNDLEKEY_WORDDATA);
                    mCurWdd = wdd;
					if(null != wdd){
						if(1 == msg.arg1) {
                            if (mDb == null)  {
                                mDb = new DictionaryCNDB(m_ct);
                            }
                            mDb.insertdictionarycache(wdd);
                            //mDb.close();
						}		
						listworddictdesc(wdd);
					}
				}
				m_svworddictdata.setVisibility(View.VISIBLE);
				m_svworddictdata.fullScroll(ScrollView.FOCUS_UP);
				m_wvdictdescitems.setVisibility(View.VISIBLE);
				m_pbdictdescwait.setVisibility(View.GONE);
				break;
                case MSG_DICTTEXTOK_EN:
                    Bundle enbd = msg.getData();
                    if(null != enbd){
                        EnWordDictDescData wdd = enbd.getParcelable(MSG_BUNDLEKEY_WORDDATA);
                        mCurEnWdd = wdd;
                        if(null != wdd){
                            if(1 == msg.arg1) {
                               if (mEnDb == null)  {
                                    mEnDb = new DictionaryENDB(m_ct);
                                }
                                mEnDb.insertDictionaryCache(wdd);
                            }
                            listEnWordDictDesc(wdd);
                        }
                    }
                    m_svworddictdata.setVisibility(View.VISIBLE);
                    m_svworddictdata.fullScroll(ScrollView.FOCUS_UP);
                    m_wvdictdescitems.setVisibility(View.VISIBLE);
                    m_pbdictdescwait.setVisibility(View.GONE);
                    break;
			case MSG_DICTTEXTERROR:
				m_svworddictdata.setVisibility(View.VISIBLE);
				m_wvdictdescitems.setVisibility(View.GONE);
				m_pbdictdescwait.setVisibility(View.GONE);
				break;
			case MSG_DICTDIMAGEERROR:
				if(View.VISIBLE == m_ivwordimage.getVisibility()) {
					//m_ivwordimage.setImageBitmap(m_bmpdictimgfailed);
                    //m_ivwordimage.setBackgroundResource(R.drawable.dictimagefailure);
                    m_ivwordimage.setImageResource(R.drawable.dictimagefailure);
				}
				break;
			}
		}
	};

/*    private void  setStrokeWord(String word) {
        MyLog.d("stroke setStrokeWord " + word);
        mStrokeView.clear();
        mStrokeData.clearOldPoints();
        MyLog.d("stroke setStrokeWord startquery " + word);
        mStrokeData.QueryContent(word);
        MyLog.d("stroke setStrokeWord endquery " + word);
        List<StrokePoint>[] outlineData = mStrokeData.getData();
        if (outlineData != null) {
            MyLog.d("stroke setStrokeWord getdata " + word);
            int count = mStrokeData.getNumStroke();
            List<StrokePoint> startPoint = mStrokeData.getStartPoints();
            List<Integer> types = mStrokeData.getTypes();
            mStrokeView.setData(outlineData, count, startPoint, types);
            mStrokeView.setSpeedLevel(20);
            mStrokeView.resume();
        }
    }*/

    private void setStrokeWord(String word) {
        mStrokeView.continueNextStroke();
        mStrokeView.stopStrokeAnimation();
        mStrokeView.ReSet();
        mStrokeView.SetText("1", word);
        mStrokeView.setReadOnly(true);
        mStrokeView.enableSmoothContour(true);
        mStrokeView.setZhuBiMode(false);
        mStrokeView.m_bShowStroke = false;
        mStrokeView.m_bShowOutline = false;
        mStrokeView.showStrokeAnimation();

    }

    private void setKeyWord(final String keyWord) {
        m_keywordLayout.removeAllViews();
        m_vwdp_pinyin.setText(null);
        if (keyWord == null) return;
        int char_num = keyWord.length();
        boolean haveStrokeDB = FileUtil.checkSupportDownload(m_ct, "stroke") && StrokeProvider.loadDB(m_ct);

        if(mEnglishPage){
            setDict(haveStrokeDB,keyWord,mEnglishPage);
        }else{
            for (int i = 0; i < char_num; i++) {
                setDict(haveStrokeDB,keyWord.substring(i, i + 1),mEnglishPage);
            }
        }
    }

    private void  setDict(boolean  haveStrokeDB,String keyWordStr,boolean en){
            TextView wordview = new TextView(m_ct);
            wordview.setLines(1);
            wordview.setText(keyWordStr);
            wordview.setTextColor(m_ct.getResources().getColor(R.color.worddict_keyword_textcolor));
            if (en) {
                wordview.setGravity(Gravity.LEFT);
            } else {
                wordview.setGravity(Gravity.CENTER);
            }
            //wordview.setTextSize(m_ct.getResources().getDimension(R.dimen.worddict_keyword_fontsize, Unit.);
            wordview.setTextSize(TypedValue.COMPLEX_UNIT_PX, m_ct.getResources().getDimension(R.dimen.worddict_keyword_fontsize));
            wordview.setIncludeFontPadding(false);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            lp.width = (int) m_ct.getResources().getDimension(R.dimen.worddict_keyword_width);
            lp.height = lp.width;
            if(en){
                lp.width = LinearLayout.LayoutParams.WRAP_CONTENT;
                lp.height = lp.width;
            }
            lp.rightMargin = (int) m_ct.getResources().getDimension(R.dimen.stroke_keyword_inteval);
            m_keywordLayout.addView(wordview, lp);

        if (haveStrokeDB) {
            Vector<StrokeRecord> strokeRecords = getRecord(keyWordStr);
            if (strokeRecords != null && strokeRecords.size() > 0) {
                wordview.setBackgroundResource(R.drawable.keyword_bg);
                wordview.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        TextView textView = (TextView) v;
                        String keyword = textView.getText().toString();
                        if (mStrokeShow.get() < 0) {
                            return;
                        } else if (mStrokeShow.get() == 0) {
                            mStrokeWord = keyword;
                            RelativeLayout.LayoutParams rp = (RelativeLayout.LayoutParams) mStrokeView.getLayoutParams();
                            if (rp != null) {
                                View parentview = (View) mStrokeLayout.getParent();
                                rp.width = parentview.getWidth();
                                rp.height = rp.width;
                                mStrokeView.setLayoutParams(rp);
                            }

                            //mStrokeLayout.startAnimation(mStrokeInAnim);
                            mStrokeShow.set(1);
                            mStrokeLayout.setVisibility(View.VISIBLE);
                            mStrokeLayout.startAnimation(mStrokeInAnim);

                            //mStrokeLayout.setAnimation(mStrokeInAnim);
                            //mStrokeInAnim.startNow();
                        } else if (mStrokeShow.get() == 1) {
                            mStrokeWord = keyword;
                        } else {   //mStrokeShow.get() == 2
                            if (!TextUtils.isEmpty(mStrokeWord) && mStrokeWord.equals(keyword)) {
                                mStrokeShow.set(-1);
                                mStrokeLayout.startAnimation(mStrokeOutAnim);
                                //mStrokeLayout.setAnimation(mStrokeOutAnim);
                                //mStrokeOutAnim.startNow();;
                            } else {
                                mStrokeWord = keyword;
                                setStrokeWord(mStrokeWord);
                            }
                        }

                    }
                });
                strokeRecords.clear();
                strokeRecords = null;
            }
        }
    }

	
	private boolean listworddictdesc(WordDictdescData wdd) {
		if(TextUtils.isEmpty(wdd.m_sbaseword) || TextUtils.isEmpty(wdd.m_swordpinyin)){
			return false;
		}
        setKeyWord(wdd.m_sbaseword);
/*
		int ipinyinleftmargin = 0;
		m_tvbaseword.setbasewordtext(wdd.m_sbaseword, true);
        LinearLayout.LayoutParams llp = (LinearLayout.LayoutParams)m_tvbaseword.getLayoutParams();
        if(null != llp) {
            llp.leftMargin = m_tvbaseword.getviewwidth() / m_tvbaseword.length();
            llp.width = m_tvbaseword.getviewwidth();
            llp.height = m_tvbaseword.getviewHeight();
            llp.bottomMargin = m_iworkregionYmargins;
            m_tvbaseword.setLayoutParams(llp);
            ipinyinleftmargin = llp.leftMargin;
        }
*/



        adjustwordsoundimageposition(/*llp, */wdd);
        //tempdostrokemp4(llp, wdd.m_sbaseword);
		
		String spy = wdd.m_swordpinyin;
		if(null != wdd.m_dicts) {
			for(WordDictdescData.WordOneDictData item : wdd.m_dicts){
				if(null != item &&
                        ((mDictMode == DICT_MODE_CNCN && item.m_type.equalsIgnoreCase("cn"))
                        || (mDictMode == DICT_MODE_CNEN && item.m_type.equalsIgnoreCase("en"))) ) {
					if(!TextUtils.isEmpty(item.m_spinyin)) {
						spy = item.m_spinyin;
						break;
					}
				}
			}
		}
/*		m_vwdp_pinyin.setindicatedtext(utils.makepinyinforonlinequery(spy), true);
		llp = (LinearLayout.LayoutParams)m_vwdp_pinyin.getLayoutParams();
		if(null != llp) {
			llp.leftMargin = ipinyinleftmargin;
			llp.bottomMargin = m_iworkregionYmargins;
			llp.width = m_vwdp_pinyin.getviewwidth();
			llp.height = m_vwdp_pinyin.getviewHeight();
			m_vwdp_pinyin.setLayoutParams(llp);
		}*/
        //m_vwdp_pinyin.setText(pinyin.convertpinyin(utils.makepinyinforonlinequery(spy)));



       String temp =makepinyinforonlinequery(spy);
        if (!TextUtils.isEmpty(temp)) {
           String newtemp = temp.trim();
            String pinyin = PinyinConvert.convert(newtemp);
            m_vwdp_pinyin.setText(pinyin);
        }

        if(null != wdd.m_dicts) {
            for(WordDictdescData.WordOneDictData item : wdd.m_dicts){
                if(null != item &&
                        ((mDictMode == DICT_MODE_CNCN && item.m_type.equalsIgnoreCase("cn"))
                                || (mDictMode == DICT_MODE_CNEN && item.m_type.equalsIgnoreCase("en"))) ) {
                    if(!TextUtils.isEmpty(item.m_sdictimageurl)) {
                        if(null == m_bmpcache || null == m_loader) {
                            m_bmpcache = new BitmapCache();
                            m_loader = new ImageLoader(m_rqvolleyref, m_bmpcache);
                        }
                        try{
                            //String svalue = m_sdictimgprefixurl + wdd.m_spriorityimgurl;
                            m_ivwordimage.setImageUrl(m_sdictimgprefixurl + item.m_sdictimageurl, m_loader, DefaultSettings.CACHE_DELTA_ONE_DAY * 365 * 70);
                            m_hscroolwebviewtotop.sendEmptyMessageDelayed(0, 200);
                        }catch(Exception e){
                        }
                        m_ivwordimage.setVisibility(View.VISIBLE);
                    } else {
                        m_ivwordimage.setVisibility(View.GONE);
                    }
                }
            }
        }

        boolean getDictData = false;
        if(null != wdd.m_dicts) {
            for(WordDictdescData.WordOneDictData item : wdd.m_dicts){
                if(null != item &&
                        ((mDictMode == DICT_MODE_CNCN && item.m_type.equalsIgnoreCase("cn"))
                                || (mDictMode == DICT_MODE_CNEN && item.m_type.equalsIgnoreCase("en"))) ) {
                    WordDictdescData.WordDictdescItemJieShi[] wdijss = null;
                    getDictData = true;
                    if(null != wdd.m_dicts){
                        for(int i = 0; i < wdd.m_dicts.length; i++) {
                            if(null != wdd.m_dicts[i] && /*null != wdd.m_items[i].m_jieshis*/
                                    (((mDictMode == DICT_MODE_CNCN && wdd.m_dicts[i].m_type.equalsIgnoreCase("cn"))
                                            || (mDictMode == DICT_MODE_CNEN && wdd.m_dicts[i].m_type.equalsIgnoreCase("en")))) ) {
                                wdijss = wdd.m_dicts[i].m_items[0].m_jieshis;
                            }
                        }
                    }
                    if(null != wdijss) {
                        String smsg = GenerateDictdescText.generateDictionarydescriptionText(wdijss, m_ct.getResources().getInteger(R.integer.worddict_webview_fontsize),
                                m_ct.getResources().getColor(R.color.worddict_webview_jieshi), m_ct.getResources().getColor(R.color.worddict_webview_liju));
                        m_wvdictdescitems.loadDataWithBaseURL(null, smsg, "text/html", "utf-8", null);
                    } else {
                        m_wvdictdescitems.loadDataWithBaseURL(null, "", "text/html", "utf-8", null);
                    }
                }
            }
        }

        if (!getDictData) {
            m_wvdictdescitems.loadDataWithBaseURL(null, "", "text/html", "utf-8", null);
            m_vwdp_pinyin.setText(null);
            m_ivwordimage.setVisibility(View.GONE);
        }

		m_wvdictdescitems.scrollTo(0, 0);

		return true;
	}

    private  String makepinyinforonlinequery(String spy) {
        String newspy = "";
        if(!TextUtils.isEmpty(spy)) {
            String ss[] = spy.split(" ");
            if(null != ss && ss.length > 0) {
                for(String s : ss){
                    if(!TextUtils.isEmpty(s)){
                        int ipos = s.indexOf('/');
                        if(ipos >= 0) {
                            s = s.substring(0, ipos);
                        }
                        newspy += s + " ";
                    }
                }
            }
            newspy = newspy.trim();
        }
        return newspy;
    }

    private boolean listEnWordDictDesc(EnWordDictDescData wdd) {
        if(TextUtils.isEmpty(wdd.mBaseWord)){
            return false;
        }
        setKeyWord(wdd.mBaseWord);

        adjustEnWordSoundImagePosition(wdd);

        String yinbiao = "";
        if(null != wdd.mDicts) {
            for(EnWordDictDescData.EnWordDictData dict : wdd.mDicts){
                if(null != dict) {
                    if(!TextUtils.isEmpty(dict.mYinBiao)) {
                        yinbiao = dict.mYinBiao;
                        break;
                    }
                }
            }
        }
        m_vwdp_pinyin.setText(yinbiao);


        boolean getDictData = false;
        if(null != wdd.mDicts) {
            for(EnWordDictDescData.EnWordDictData dict : wdd.mDicts){
                if(null != dict) {
                    EnWordDictDescData.EnWordCiXingData[] cixings = dict.mCiXings;
                    getDictData = true;

                    if(null != cixings) {
                        String smsg = GenerateDictdescText.generateEnDictionaryDescriptionText(cixings, m_ct.getResources().getInteger(R.integer.worddict_webview_fontsize),
                                m_ct.getResources().getColor(R.color.worddict_webview_jieshi), m_ct.getResources().getColor(R.color.worddict_webview_liju));
                        m_wvdictdescitems.loadDataWithBaseURL(null, smsg, "text/html", "utf-8", null);
                    } else {
                        m_wvdictdescitems.loadDataWithBaseURL(null, "", "text/html", "utf-8", null);
                    }
                    break;
                }
            }
        }

        if (!getDictData) {
            m_wvdictdescitems.loadDataWithBaseURL(null, "", "text/html", "utf-8", null);
            m_vwdp_pinyin.setText(null);
            m_ivwordimage.setVisibility(View.GONE);
        }

        m_wvdictdescitems.scrollTo(0, 0);

        return true;
    }

	
	private Handler m_hscroolwebviewtotop = new Handler() {
		@Override
		public void handleMessage(Message msg){
			if(null != m_wvdictdescitems && View.VISIBLE == m_wvdictdescitems.getVisibility()) {
				m_wvdictdescitems.scrollTo(0, 0);
			}
		}
	};




    private   WordDictdescData newreadtextdescfromdatabase(final int ibookid, final int ibooknetid, final int iviewid, final String sword, final String swordpinyin) {
        if(ibookid < 0 || ibooknetid < 0 || TextUtils.isEmpty(sword) || TextUtils.isEmpty(swordpinyin)){
            return null;
        }

        if (mDb == null)  {
            mDb = new DictionaryCNDB(m_ct);
        }

        IntDouble[] idudicts = mDb.getworddictrangewithoutnetid(sword, swordpinyin);
        if (null == idudicts) {
            return null;
        }

        WordDictdescData wddoutput = new WordDictdescData();
        wddoutput.m_inetid = ibooknetid;
        wddoutput.m_ibookid = ibookid;
        wddoutput.m_sbaseword = sword;
        wddoutput.m_swordpinyin = swordpinyin;
        wddoutput.m_iviewId = iviewid;
        wddoutput.m_sdictname = mDb.getworddictnamewithoutnetid(wddoutput.m_sbaseword, swordpinyin);
        wddoutput.m_dicts = new  WordDictdescData.WordOneDictData[idudicts.length];
        for (int i = 0; i < idudicts.length; i++) {
            wddoutput.m_dicts[i] = new WordDictdescData.WordOneDictData();
            wddoutput.m_dicts[i].m_dictId = i;
            if (wddoutput.m_ssduyin == null) {
                String sduyin = mDb.getworddictduyinurlwithoutnetid(i, wddoutput.m_sbaseword, idudicts[i].m_ival1, idudicts[i].m_ival2);
                if(null != sduyin) {
                    if(sduyin.endsWith(";")){
                        sduyin = sduyin.substring(0, sduyin.length() - 1);
                        wddoutput.m_ssduyin = sduyin.split(";");
                    }
                }
            }
            wddoutput.m_dicts[i].m_type = mDb.getworddicttypewithoutnetid(i, wddoutput.m_sbaseword, idudicts[i].m_ival1, idudicts[i].m_ival2);
            wddoutput.m_dicts[i].m_sdictimageurl = mDb.getworditemshiyiimageurlwithoutnetid(i, -1, wddoutput.m_sbaseword, idudicts[i].m_ival1, idudicts[i].m_ival2);
            wddoutput.m_dicts[i].m_spinyin = mDb.getworditemshiyipinyinwithoutnetid(i, -1, wddoutput.m_sbaseword, idudicts[i].m_ival1, idudicts[i].m_ival2);
            IntDouble[] dictitemranges = mDb.getwordictitemrangeswithoutnetid(i, wddoutput.m_sbaseword, idudicts[i].m_ival1, idudicts[i].m_ival2);
            if (dictitemranges != null  && dictitemranges.length > 0) {
                wddoutput.m_dicts[i].m_items = new WordDictdescData.WordDictdescItem[dictitemranges.length];
                for (int j = 0; j < dictitemranges.length; j++) {

                    wddoutput.m_dicts[i].m_items[j] = new WordDictdescData.WordDictdescItem();
                    wddoutput.m_dicts[i].m_items[j].m_itemId = j;
                    wddoutput.m_dicts[i].m_items[j].m_spinyin = mDb.getworditemshiyipinyinwithoutnetid(i, j, wddoutput.m_sbaseword, dictitemranges[j].m_ival1, dictitemranges[j].m_ival2);
                    //wddoutput.m_items[i].m_spinyin = db.getworditemshiyipinyin(ibooknetid, i, wddoutput.m_sbaseword);
                    wddoutput.m_dicts[i].m_items[j].m_sdictimageurl = mDb.getworditemshiyiimageurlwithoutnetid(i,j, wddoutput.m_sbaseword, dictitemranges[j].m_ival1, dictitemranges[j].m_ival2);
                    //wddoutput.m_items[i].m_sdictimageurl = db.getworditemshiyiimageurl(ibooknetid, i, wddoutput.m_sbaseword);
             /*       if(!TextUtils.isEmpty(wddoutput.m_dicts[i].m_items[j].m_sdictimageurl) && TextUtils.isEmpty(wddoutput.m_spriorityimgurl)){
                        wddoutput.m_spriorityimgurl = wddoutput.m_dicts[i].m_items[j].m_sdictimageurl;
                    }
               /*     String sduyin = mDb.getworditemduyinurlwithoutnetid(i, wddoutput.m_sbaseword, iduitems[i].m_ival1, iduitems[i].m_ival2);
                    if(null != sduyin) {
                        if(sduyin.endsWith(";")){
                            sduyin = sduyin.substring(0, sduyin.length() - 1);
                        }
                        wddoutput.m_ssduyin = sduyin.split(";");
                    }*/
                    IntDouble[] idushiyiranges = mDb.getworditemshiyirangeswithoutnetid(i, j, wddoutput.m_sbaseword, dictitemranges[j].m_ival1, dictitemranges[j].m_ival2);
                    //IntDouble[] idushiyiranges = getworditemshiyiranges(ibooknetid, i, wddoutput.m_sbaseword, iduitems[i].m_ival1, iduitems[i].m_ival2);
                    if(null != idushiyiranges && idushiyiranges.length > 0) {
                        wddoutput.m_dicts[i].m_items[j].m_jieshis = new WordDictdescData.WordDictdescItemJieShi[idushiyiranges.length];
                        for(int k = 0; k < idushiyiranges.length; k++) {

                            wddoutput.m_dicts[i].m_items[j].m_jieshis[k] = new WordDictdescData.WordDictdescItemJieShi();
                            wddoutput.m_dicts[i].m_items[j].m_jieshis[k].m_sshiyi = mDb.getwordshiyibydatabaseid(idushiyiranges[k].m_ival1);
                            ArrayList<WordDictdescData.ParcelableCizu> aloutcizu = new ArrayList<WordDictdescData.ParcelableCizu>();
                            ArrayList<WordDictdescData.ParcelableCizu> aloutliju = new ArrayList<WordDictdescData.ParcelableCizu>();
                            mDb.getwordspecificcizusandliju(idushiyiranges[k].m_ival1 + 1, idushiyiranges[k].m_ival2, aloutcizu, aloutliju);
                            if(aloutcizu.size() > 0) {
                                wddoutput.m_dicts[i].m_items[j].m_jieshis[k].m_cizus = new WordDictdescData.ParcelableCizu[aloutcizu.size()];
                                for(int m = 0; m < aloutcizu.size(); m++) {
                                    wddoutput.m_dicts[i].m_items[j].m_jieshis[k].m_cizus[m] = aloutcizu.get(m);
                                }
                            }
                            else{
                                wddoutput.m_dicts[i].m_items[j].m_jieshis[k].m_cizus = null;
                            }
                            if(aloutliju.size() > 0){
                                wddoutput.m_dicts[i].m_items[j].m_jieshis[k].m_lijus =  new WordDictdescData.ParcelableCizu[aloutliju.size()];
                                for(int m = 0; m < aloutliju.size(); m++) {
                                    wddoutput.m_dicts[i].m_items[j].m_jieshis[k].m_lijus[m] = aloutliju.get(m);
                                }
                            }
                            else{
                                wddoutput.m_dicts[i].m_items[j].m_jieshis[k].m_lijus = null;
                            }
                        }
                    }
                }
            }
        }

        return wddoutput;
    }

    private   EnWordDictDescData readEnWordDescFromDatabase(final int ibookid, final int ibooknetid, final int iviewid, final String sentence, final int wordindex, String clickword, boolean blur) {
        if(ibookid < 0 || ibooknetid < 0 || TextUtils.isEmpty(sentence) || wordindex < 0){
            return null;
        }

        if (mEnDb == null)  {
            mEnDb = new DictionaryENDB(m_ct);
        }

        IntDouble[] idudicts = mEnDb.getWordDictRange(ibookid, sentence, wordindex, clickword, blur);
        if (null == idudicts) {
            return null;
        }

        EnWordDictDescData wddoutput = new EnWordDictDescData();
        wddoutput.m_inetid = ibooknetid;
        wddoutput.m_ibookid = ibookid;
        wddoutput.mPhrases = sentence;
        wddoutput.mPhraseIndex = wordindex;

        wddoutput.m_iviewId = iviewid;

        wddoutput.mDicts = new  EnWordDictDescData.EnWordDictData[idudicts.length];
        for (int i = 0; i < idudicts.length; i++) {
            wddoutput.mDicts[i] = new EnWordDictDescData.EnWordDictData();
            wddoutput.mDicts[i].mDictId = i;

            if (wddoutput.mBaseWord == null) {
                wddoutput.mBaseWord = mEnDb.getWordDictBaseWord(i,ibookid, sentence, wordindex, idudicts[i].m_ival1, idudicts[i].m_ival2);
            }

            if (wddoutput.m_ssduyin == null) {
                String sduyin = mEnDb.getWordDictDuyinUrl(i, ibookid, sentence, wordindex, idudicts[i].m_ival1, idudicts[i].m_ival2);
                if(null != sduyin) {
                    if(sduyin.endsWith(";")){
                        sduyin = sduyin.substring(0, sduyin.length() - 1);
                        wddoutput.m_ssduyin = sduyin.split(";");
                    }
                }
            }

            wddoutput.mDicts[i].mDictType = mEnDb.getWordDictType(i, ibookid, sentence, wordindex, idudicts[i].m_ival1, idudicts[i].m_ival2);
            wddoutput.mDicts[i].mDictName = mEnDb.getWordDictName(i, ibookid, sentence, wordindex, idudicts[i].m_ival1, idudicts[i].m_ival2);
            wddoutput.mDicts[i].mYinBiao = mEnDb.getWordDictYinBiao(i, ibookid, sentence, wordindex, idudicts[i].m_ival1, idudicts[i].m_ival2);

            IntDouble[] dictcixingranges = mEnDb.getWorDictCixingRanges(i, ibookid, sentence, wordindex, idudicts[i].m_ival1, idudicts[i].m_ival2);
            if (dictcixingranges != null  && dictcixingranges.length > 0) {
                wddoutput.mDicts[i].mCiXings = new EnWordDictDescData.EnWordCiXingData[dictcixingranges.length];
                for (int j = 0; j < dictcixingranges.length; j++) {

                    wddoutput.mDicts[i].mCiXings[j] = new EnWordDictDescData.EnWordCiXingData();
                    wddoutput.mDicts[i].mCiXings[j].mCiXingId = j;

                    wddoutput.mDicts[i].mCiXings[j].mCXdecs = mEnDb.getWordDictCixingDesc(i, j, ibookid, sentence, wordindex, dictcixingranges[j].m_ival1, dictcixingranges[j].m_ival2);
                    wddoutput.mDicts[i].mCiXings[j].mFuShu = mEnDb.getWordDictCixingFushu(i, j, ibookid, sentence, wordindex, dictcixingranges[j].m_ival1, dictcixingranges[j].m_ival2);

                    IntDouble[] jishiranges = mEnDb.getWordDictCiXingJieShiRanges(i, j, ibookid, sentence, wordindex, dictcixingranges[j].m_ival1, dictcixingranges[j].m_ival2);
                    if(null != jishiranges && jishiranges.length > 0) {
                        wddoutput.mDicts[i].mCiXings[j].mJieShis = new EnWordDictDescData.EnWordJieshiData[jishiranges.length];
                        for(int k = 0; k < jishiranges.length; k++) {

                            wddoutput.mDicts[i].mCiXings[j].mJieShis[k] = new EnWordDictDescData.EnWordJieshiData();
                            wddoutput.mDicts[i].mCiXings[j].mJieShis[k].mShiYi = mEnDb.getWordDictCiXingJieShiByDataBaseId(jishiranges[k].m_ival1);

                            ArrayList<EnWordDictDescData.EnParcelableCizu> aloutliju = new ArrayList<EnWordDictDescData.EnParcelableCizu>();
                            mEnDb.getWordDictCiXingJieShiLiJus(jishiranges[k].m_ival1 + 1, jishiranges[k].m_ival2, aloutliju);

                            if(aloutliju.size() > 0){
                                wddoutput.mDicts[i].mCiXings[j].mJieShis[k].mLiJus =  new EnWordDictDescData.EnParcelableCizu[aloutliju.size()];
                                for(int m = 0; m < aloutliju.size(); m++) {
                                    wddoutput.mDicts[i].mCiXings[j].mJieShis[k].mLiJus[m] = aloutliju.get(m);
                                }
                            }
                            else{
                                wddoutput.mDicts[i].mCiXings[j].mJieShis[k].mLiJus = null;
                            }
                        }
                    }
                }
            }
        }

        return wddoutput;
    }


    /**
     * 中文取词 cn
     * 英文取词 en
     * @param ibookid
     * @param ibooknetid
     * @param iviewid
     * @param sword
     * @param spinyin
     * @return
     */
    private boolean getWorddictInfoByRequestManager(final int ibookid, final int ibooknetid, final int iviewid,
                                                    final String sword, final String spinyin) {

        ApiRequestParams  params = new ApiRequestParams();
        params.put("pid", ibooknetid);
        params.put("word", sword);
        params.put("py", spinyin);
        params.put("pf", ApiConstans.PLATFORM);
        WordDictApiResponse  cnWordDict =  new WordDictApiResponse(ibookid,ibooknetid,iviewid);
            cnWordDict.setCnParm(sword, spinyin);
        ApiWawayaya.getWordDict(m_ct, params,cnWordDict);
        return true;
    }

    private boolean getEnWorddictInfoByRequestManager(final int ibookid, final int ibooknetid,
                                                      final int iviewid, final String phreses,
                                                      final int phraseindex,final String clickword) {
        ApiRequestParams params = new ApiRequestParams();
        params.put("pid", ibooknetid);
        params.put("word", "");
        params.put("py", "");
        params.put("pf", ApiConstans.PLATFORM);
        params.put("phrase",phreses);
        params.put("phrase_idx", phraseindex);
        params.put("original_id", ibookid);

        WordDictApiResponse  enWordDict =  new WordDictApiResponse(ibookid,ibooknetid,iviewid);
          enWordDict.setEnParm(phreses, phraseindex,clickword);
        ApiWawayaya.getWordDict(m_ct,params, enWordDict);

        return true;
    }

    /**
     * 对请求返回的数据进行处理
     */
    class WordDictApiResponse implements  ApiResponseJsonListener{

        //common
        private int  ibookId,ibooknetId,iviewid;

        //en
        private  String phreses, clickword;
        private  int phraseindex;
        //cn
        private  String  sword, spinyin;

        public WordDictApiResponse(int ibookid, int ibooknetid, int iviewid){
             this.ibookId = ibookid;
             this.ibooknetId = ibooknetid;
             this.iviewid = iviewid;
        }

        public void setEnParm(String phreses, int phraseindex, String  clickword){
             this.phreses = phreses;
             this.clickword = clickword;
             this.phraseindex = phraseindex;
        }

        public void setCnParm(String sword,String spinyin){
             this.sword = sword;
             this.spinyin = spinyin;
        }

        @Override
        public void success1(ApiResponseData result) {
            if(mEnglishPage){
                Integer ii = (Integer) getTag();
                if (null != ii && ii.intValue() != m_iviewId) {
                    return;
                }
                EnWordDictDescData wdd = parseEnResponseJson(result.getRetinfo(),
                        ibookId, ibooknetId, iviewid, phreses, phraseindex, clickword);
                if (null != wdd) {
                    if (null != m_hshowworddictdata) {
                        Message msg = new Message();
                        msg.what = MSG_DICTTEXTOK_EN;
                        msg.arg1 = 1;
                        Bundle bd = new Bundle();
                        bd.putParcelable(MSG_BUNDLEKEY_WORDDATA, wdd);
                        msg.setData(bd);
                        m_hshowworddictdata.sendMessage(msg);
                    }
                }
            }else{
                Integer ii = (Integer) getTag();
                if (null != ii && ii.intValue() != m_iviewId) {
                    return;
                }
                WordDictdescData wdd = parseresponsejson(result.getRetinfo(),
                        ibookId, ibooknetId, iviewid, sword, spinyin);
                if (null != wdd) {
                    if (null != m_hshowworddictdata) {
                        Message msg = new Message();
                        msg.what = MSG_DICTTEXTOK;
                        msg.arg1 = 1;
                        Bundle bd = new Bundle();
                        bd.putParcelable(MSG_BUNDLEKEY_WORDDATA, wdd);
                        msg.setData(bd);
                        m_hshowworddictdata.sendMessage(msg);
                    }
                }
            }
        }

        @Override
        public void success0(ApiResponseData result) {
             if(mEnglishPage){
                 Integer ii = (Integer) getTag();
                 if (null != ii && ii.intValue() != m_iviewId) {
                     return;
                 }
                 setKeyWord(clickword);
                 if (null != m_hshowworddictdata) {
                     m_hshowworddictdata.sendEmptyMessage(MSG_DICTTEXTERROR);
                     m_hshowworddictdata.sendEmptyMessage(MSG_DICTDIMAGEERROR);
                 }
             }else{
                 Integer ii = (Integer) getTag();
                 if (null != ii && ii.intValue() != m_iviewId) {
                     return;
                 }
                 if (null != m_hshowworddictdata) {
                     m_hshowworddictdata.sendEmptyMessage(MSG_DICTTEXTERROR);
                     m_hshowworddictdata.sendEmptyMessage(MSG_DICTDIMAGEERROR);
                 }
             }
        }

        @Override
        public void error(ApiResponseData result) {
                Integer ii = (Integer) getTag();
                if (null != ii && ii.intValue() != m_iviewId) {
                    return;
                }
                if (null != m_hshowworddictdata) {
                    m_hshowworddictdata.sendEmptyMessage(MSG_DICTTEXTERROR);
                    m_hshowworddictdata.sendEmptyMessage(MSG_DICTDIMAGEERROR);
                }
        }
    }

	private WordDictdescData parseresponsejson(JSONObject jo, final int ibookid, final int ibooknetid, final int iviewid, final String sword, final String spinyin) {
		WordDictdescData wdd = new WordDictdescData();
		wdd.m_ibookid = ibookid;
		wdd.m_inetid = ibooknetid;
		wdd.m_iviewId = iviewid;
		wdd.m_sbaseword = sword;
		wdd.m_swordpinyin = spinyin;
		try {
			if(TextUtils.isEmpty(wdd.m_sbaseword) || !wdd.m_sbaseword.contentEquals(jo.getString(jsondict_key_word))) {
				wdd = null;
				return wdd;
			}			
			JSONArray ja = jo.getJSONArray(jsondict_key_dicts);
			int idictssize = ja.length();
			for(int i = 0; i < idictssize; i++) {
                if (idictssize > 0 && wdd.m_dicts == null) {
                    wdd.m_dicts = new WordDictdescData.WordOneDictData[idictssize];
                }
                wdd.m_dicts[i] = new WordDictdescData.WordOneDictData();
				JSONObject josub = ja.getJSONObject(i);
                wdd.m_dicts[i].m_type = josub.getString(jsondict_key_type);
                wdd.m_dicts[i].m_dictId = i;

				//wdd.m_sdictname = josub.getString(jsondict_key_name);
				JSONArray jaitems = josub.getJSONArray(jsondict_key_items);
				int iitemssize = jaitems.length();
				if(iitemssize > 0 && wdd.m_dicts[i].m_items == null) {
					wdd.m_dicts[i].m_items = new WordDictdescData.WordDictdescItem[iitemssize];
				}
				for(int j = 0; j < iitemssize; j++) {
					wdd.m_dicts[i].m_items[j] = new WordDictdescData.WordDictdescItem();
					wdd.m_dicts[i].m_items[j].m_itemId = j;
					JSONObject joitem = jaitems.getJSONObject(j);
					wdd.m_dicts[i].m_items[j].m_spinyin = joitem.getString(jsondict_key_pin_yin);
                    if (!TextUtils.isEmpty(wdd.m_dicts[i].m_items[j].m_spinyin)) {
                        wdd.m_dicts[i].m_spinyin = wdd.m_dicts[i].m_items[j].m_spinyin;
                    }
					wdd.m_dicts[i].m_items[j].m_sdictimageurl = joitem.getString(jsondict_key_peitu);
					if(!TextUtils.isEmpty(wdd.m_dicts[i].m_items[j].m_sdictimageurl)) {
                        wdd.m_dicts[i].m_items[j].m_sdictimageurl = wdd.m_dicts[i].m_items[j].m_sdictimageurl.replace("[", "");
                        wdd.m_dicts[i].m_items[j].m_sdictimageurl = wdd.m_dicts[i].m_items[j].m_sdictimageurl.replace("]", "");
                        wdd.m_dicts[i].m_items[j].m_sdictimageurl = wdd.m_dicts[i].m_items[j].m_sdictimageurl.replace("\\/", "/");
                        wdd.m_dicts[i].m_items[j].m_sdictimageurl = wdd.m_dicts[i].m_items[j].m_sdictimageurl.replace("\"", "");
                        if(TextUtils.isEmpty(wdd.m_dicts[i].m_sdictimageurl)){
                            if(!TextUtils.isEmpty(wdd.m_dicts[i].m_items[j].m_sdictimageurl) && (wdd.m_dicts[i].m_items[j].m_sdictimageurl.startsWith("http://") || wdd.m_dicts[i].m_items[j].m_sdictimageurl.startsWith("/"))) {
                                wdd.m_dicts[i].m_sdictimageurl = wdd.m_dicts[i].m_items[j].m_sdictimageurl;
                                //wdd.m_spriorityimgurl = wdd.m_dicts[j].m_sdictimageurl;
                            }
                        }
                    }
					//String sfanyici = joitem.getString(jsondict_key_fanyic);
					JSONArray jajieshis = joitem.getJSONArray(jsondict_key_jie_shi);
					int ijeishisize = jajieshis.length();
					if(ijeishisize > 0){
						wdd.m_dicts[i].m_items[j].m_jieshis = new WordDictdescData.WordDictdescItemJieShi[ijeishisize];
					}
					for(int k = 0; k < ijeishisize; k++) {
						wdd.m_dicts[i].m_items[j].m_jieshis[k] = new WordDictdescData.WordDictdescItemJieShi();
						JSONObject jojieshi = jajieshis.getJSONObject(k);
						wdd.m_dicts[i].m_items[j].m_jieshis[k].m_sshiyi = jojieshi.getString(jsondict_key_str);
						JSONArray jaduanyus = jojieshi.getJSONArray(jsondict_key_duan_yu);
						int iduanyusize = jaduanyus.length();
						if(iduanyusize > 0) {
							wdd.m_dicts[i].m_items[j].m_jieshis[k].m_cizus = new WordDictdescData.ParcelableCizu[iduanyusize];
						}
						for(int m = 0; m < iduanyusize; m++) {
							JSONObject joduanyu = jaduanyus.getJSONObject(m);
							wdd.m_dicts[i].m_items[j].m_jieshis[k].m_cizus[m] = new WordDictdescData.ParcelableCizu();
							wdd.m_dicts[i].m_items[j].m_jieshis[k].m_cizus[m].m_cizu = joduanyu.getString(jsondict_key_chs);
							wdd.m_dicts[i].m_items[j].m_jieshis[k].m_cizus[m].m_cizujieshi = joduanyu.getString(jsondict_key_eng);
						}
						JSONArray jalijus = jojieshi.getJSONArray(jsondict_key_li_ju);
						int ilijusize = jalijus.length();
						if(ilijusize > 0) {
							wdd.m_dicts[i].m_items[j].m_jieshis[k].m_lijus = new WordDictdescData.ParcelableCizu[ilijusize];
						}
						for(int n = 0; n < ilijusize; n++) {
							JSONObject joliju = jalijus.getJSONObject(n);
							wdd.m_dicts[i].m_items[j].m_jieshis[k].m_lijus[n] = new WordDictdescData.ParcelableCizu();
							wdd.m_dicts[i].m_items[j].m_jieshis[k].m_lijus[n].m_cizu = joliju.getString(jsondict_key_chs);
							wdd.m_dicts[i].m_items[j].m_jieshis[k].m_lijus[n].m_cizujieshi = joliju.getString(jsondict_key_eng);
						}
					}
				}
			}
			try{
				JSONArray jaduyin = jo.getJSONArray(jsondict_key_duyins);
				wdd.m_ssduyin = new String[jaduyin.length()];
				for(int i = 0; i < jaduyin.length(); i++){
					wdd.m_ssduyin[i] = jaduyin.getString(i);
				}
			}catch(Exception e){
			}
		} catch (JSONException je) {
			wdd = null;
			TLog.log("NewViewWordDictdesc : postresponsejson : je : " + je);
		} catch(Exception e){
			wdd = null;
			TLog.log("NewViewWordDictdesc : postresponsejson : e : " + e);
		}
		return wdd;
	}

    private EnWordDictDescData parseEnResponseJson(JSONObject jo, final int ibookid,final int ibooknetid,  final int iviewid, final String phrases,
                                                   final int phraseindex, final String clickword) {
        EnWordDictDescData wdd = new EnWordDictDescData();
        wdd.m_ibookid = ibookid;
        wdd.m_inetid = ibooknetid;
        wdd.m_iviewId = iviewid;
        wdd.mPhraseIndex = phraseindex;
        wdd.mPhrases = phrases;
        wdd.mClickWord = clickword;
        try {
            wdd.mBaseWord = jo.getString(jsondict_key_word);
            JSONArray ja = jo.getJSONArray(jsondict_key_dicts);
            int idictssize = ja.length();
            for(int i = 0; i < idictssize; i++) {
                if (idictssize > 0 && wdd.mDicts == null) {
                    wdd.mDicts = new EnWordDictDescData.EnWordDictData[idictssize];
                }
                wdd.mDicts[i] = new EnWordDictDescData.EnWordDictData();
                JSONObject josub = ja.getJSONObject(i);
                wdd.mDicts[i].mDictType = josub.getString(jsondict_key_type);
                wdd.mDicts[i].mDictId = i;
                wdd.mDicts[i].mDictName = josub.getString(jsondict_key_name);
                wdd.mDicts[i].mYinBiao = josub.getString(jsondict_key_yinbiao);


                JSONArray jacixings = josub.getJSONArray(jsondict_key_cixing);
                int iitemssize = jacixings.length();
                if(iitemssize > 0 && wdd.mDicts[i].mCiXings == null) {
                    wdd.mDicts[i].mCiXings = new EnWordDictDescData.EnWordCiXingData[iitemssize];
                }
                for(int j = 0; j < iitemssize; j++) {
                    wdd.mDicts[i].mCiXings[j] = new EnWordDictDescData.EnWordCiXingData();
                    wdd.mDicts[i].mCiXings[j].mCiXingId = j;
                    JSONObject jocixing = jacixings.getJSONObject(j);
                    wdd.mDicts[i].mCiXings[j].mCXdecs = jocixing.getString(jsondict_key_cx);
                    wdd.mDicts[i].mCiXings[j].mFuShu = jocixing.getString(jsondict_key_fushu);

                    JSONArray jajieshis = jocixing.getJSONArray(jsondict_key_jie_shi);
                    int ijeishisize = jajieshis.length();

                    if(ijeishisize > 0){
                        wdd.mDicts[i].mCiXings[j].mJieShis = new EnWordDictDescData.EnWordJieshiData[ijeishisize];
                    }
                    for(int k = 0; k < ijeishisize; k++) {
                        wdd.mDicts[i].mCiXings[j].mJieShis[k] = new EnWordDictDescData.EnWordJieshiData();
                        JSONObject jojieshi = jajieshis.getJSONObject(k);
                        wdd.mDicts[i].mCiXings[j].mJieShis[k].mShiYi = jojieshi.getString(jsondict_key_js);

                        if (jojieshi.has(jsondict_key_li_ju)) {
                            JSONArray jalijus = jojieshi.getJSONArray(jsondict_key_li_ju);
                            int ilijusize = jalijus.length();
                            if (ilijusize > 0) {
                                wdd.mDicts[i].mCiXings[j].mJieShis[k].mLiJus = new EnWordDictDescData.EnParcelableCizu[ilijusize];
                            }
                            for (int n = 0; n < ilijusize; n++) {
                                JSONObject joliju = jalijus.getJSONObject(n);
                                wdd.mDicts[i].mCiXings[j].mJieShis[k].mLiJus[n] = new EnWordDictDescData.EnParcelableCizu();
                                wdd.mDicts[i].mCiXings[j].mJieShis[k].mLiJus[n].mLiJu = joliju.getString(jsondict_key_lj);
                                wdd.mDicts[i].mCiXings[j].mJieShis[k].mLiJus[n].mLiJuJieShi = joliju.getString(jsondict_key_lj_js);
                            }
                        }
                    }
                }
            }
            try{
                JSONArray jaduyin = jo.getJSONArray(jsondict_key_duyins);
                wdd.m_ssduyin = new String[jaduyin.length()];
                for(int i = 0; i < jaduyin.length(); i++){
                    wdd.m_ssduyin[i] = jaduyin.getString(i);
                }
            }catch(Exception e){
            }
        } catch (JSONException je) {
            wdd = null;
            TLog.log("NewViewWordDictdesc : postresponsejson : je : " + je);
        } catch(Exception e){
            wdd = null;
            TLog.log("NewViewWordDictdesc : postresponsejson : e : " + e);
        }
        return wdd;
    }

/*
	private int getscaledfontsize(int ifontsize) {
		return utils.getscaledfontsize(ifontsize, Math.min(m_fratiox, m_fratioy), m_dsi.m_fscreendensity);
	}	

	private int getscaledsize(int idefaultsize){
		return (int)(idefaultsize * m_dsi.m_fscreendensity * Math.min(m_fratiox, m_fratioy));
	}
		*/
	private String convetsoundurltosdcardpath(String surl){
		try {
			String sfolder = FileUtil.getireadckclocaldictionaryfolder(FileUtil.getparentfolder(AppContext.bookzipsavedpath));
			int ipos = surl.lastIndexOf(File.separator);
			if(ipos > 0) {
				try{
					new File(sfolder + File.separator + surl.substring(0, ipos)).mkdirs();
				}catch(Exception e){
				}
			}
			return sfolder + surl;
		} catch (Exception e) {
		}
		return null;
	}
	
	private void startworddictsoundplay(StringDouble[] spathes){
		m_isoundspathesidx = 0;
		closeworddictsoundplay();
		startsoundanimation();
		String ssound = null;
		synchronized(this){
			if(null != m_sdsoundspathes && m_sdsoundspathes.length > 0) {
				ssound = m_sdsoundspathes[m_isoundspathesidx].m_sVal2;
				m_isoundspathesidx++;
			}
		}
		onlystartmediaplayer(ssound);
	}

	private void closeworddictsoundplay() {
		stopsoundanimation();
		onlyclosemediaplayer();
		m_isoundspathesidx = 0;
	}

	private boolean onlystartmediaplayer(String ssoundpath) {
		if(TextUtils.isEmpty(ssoundpath) || !new File(ssoundpath).exists()){
			return false;
		}
		boolean bdone = true;
		try {
			bdone = createnewmediaplayer();
			if(!bdone) {
				return false;
			}
			m_mpworddict.setDataSource(ssoundpath);
			m_mpworddict.prepare();
			m_mpworddict.start();
		} catch (IllegalArgumentException e) {
			bdone = false;
		} catch (IllegalStateException e) {
			bdone = false;
		} catch (IOException e) {
			bdone = false;
		}
		if(!bdone) {
			onlyclosemediaplayer();
		}
		return bdone;
	}
	
	private boolean createnewmediaplayer() {
		m_mpworddict = new MediaPlayer();
		m_mpworddict.setOnPreparedListener(new MediaPlayer.OnPreparedListener(){
			@Override
			public void onPrepared(MediaPlayer mp) {
			}
		});
		
		m_mpworddict.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
			@Override
			public void onCompletion(MediaPlayer mp) {
				onlyclosemediaplayer();
				if(null != m_sdsoundspathes && m_isoundspathesidx < m_sdsoundspathes.length) {
					if(onlystartmediaplayer(m_sdsoundspathes[m_isoundspathesidx].m_sVal2)){
						m_isoundspathesidx++;
						return;
					}
				}
				stopsoundanimation();
				m_isoundspathesidx = 0;
			} 
		});
		
		m_mpworddict.setOnErrorListener(new MediaPlayer.OnErrorListener(){
			@Override
			public boolean onError(MediaPlayer mp, int what, int extra) {
				onlyclosemediaplayer();
				TLog.log("NewViewWordDictdesc : createnewmediaplayer : OnErrorListener : " + what + " and " + extra);
				return false;
			}
		});
		
		return (null != m_mpworddict);
	}
	
	private synchronized void onlyclosemediaplayer() {
    	try{
    		try{
    	    	if(null != m_mpworddict) {    		
    	    		m_mpworddict.stop();
    	    		m_mpworddict.release();
    	    		m_mpworddict = null;
    			}
    		}catch(Exception e){
    		}
    	}catch(Exception e){
    	}
	}
	
	private void startsoundanimation(){
		m_bstopsound.set(false);
		m_tmdictsound = new Timer();
		m_ttdictsound = new TimerTask()  {
    	int itimercount = 0;
		@Override
	    public void run()  {
				Message msg = new Message();
				msg.what = 0;
				msg.arg1 = itimercount;
				if(0 == itimercount){
					itimercount++;
				}
				else{
					itimercount = 0;
				}
				m_hshowsoundanim.sendMessage(msg);
	        }
	    };
	    m_tmdictsound.schedule(m_ttdictsound, 0, 500);
	}
	
	private void stopsoundanimation(){
		m_bstopsound.set(true);
    	try{
			if(null != m_tmdictsound) {
				m_tmdictsound.cancel();
				m_tmdictsound = null;
			}
			if(null != m_ttdictsound) {
				m_ttdictsound.cancel();
				m_ttdictsound = null;
			}
		}catch(Exception e){
		}
	}
	
    private Handler m_hshowsoundanim = new Handler(){
    	@Override
    	public void handleMessage(Message msg) {
			if(0 == msg.arg1 && !m_bstopsound.get()){
				m_bnwordsound.setBackgroundResource(R.drawable.dictsound2);
			}
			else if(1 == msg.arg1 && !m_bstopsound.get()){
				m_bnwordsound.setBackgroundResource(R.drawable.dictsound1);
			}
    	}
    };
	
	// 2014-11-04, temporary code, must be discussed later and update it.
	//private android.widget.ImageView m_bnstroke = null;
/*	private String[] m_sfiles = null;
	private void tempdostrokemp4(LinearLayout.LayoutParams llpbaseword, String sbaseword){
		if(null == m_bnstroke) {
			m_bnstroke = (android.widget.ImageView)findViewById(R.id.bn_wordstroke);
		}
		java.util.ArrayList<String> almp4path = new java.util.ArrayList<String>();
		String sfolder;
		try {
			sfolder = utils.getireadckclocalstrokedatafolder(false, null);
		} catch (Exception e) {
			// for future function, the stroke data should be required from net again
			return;
		}
		int ilen = sbaseword.length();
		for(int i = 0; i < ilen; i++) {
			String sfile = sfolder + File.separator + sbaseword.charAt(i) + ".mp4";
			if(new File(sfile).exists()){
				almp4path.add(sfile);
			}
		}
		ilen = almp4path.size();
		if(ilen > 0) {
			m_sfiles = new String[ilen];
			for(int i = 0; i < ilen; i++) {
				m_sfiles[i] = almp4path.get(i);
			}
			LinearLayout.LayoutParams lpbn = (LinearLayout.LayoutParams)m_bnstroke.getLayoutParams();
			if(null != lpbn && null != llpbaseword){
				lpbn.width = llpbaseword.height * 2 / 3;
				lpbn.height = lpbn.width;
				lpbn.topMargin = llpbaseword.topMargin + llpbaseword.height / 6 + 1;
				lpbn.leftMargin = llpbaseword.height / 2;
				m_bnstroke.setLayoutParams(lpbn);
			}
			m_bnstroke.setVisibility(View.VISIBLE);
		}
		m_bnstroke.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent it = new Intent(m_ct, StrokeVideoActivity.class);
	        	it.putExtra(StrokeVideoActivity.KEY_STR_PATHARRAY, m_sfiles);
	        	it.putExtra(ConstValues.BUNDLE_BOOKORIENTATION, 
	        			m_dsi.m_iScreenWidth > m_dsi.m_iScreenHeight ? ConstValues.BOOK_ORIENTATION_LANDSCAPE : ConstValues.BOOK_ORIENTATION_PORTRAIT);
	        	m_ct.startActivity(it);
			}
		});
	}
	*/
/*	private void cleartempdostrokemp4() {
		m_sfiles = null;
		if(null != m_bnstroke){
			m_bnstroke.setVisibility(View.GONE);
		}
	}*/

    @Override
    public Vector<StrokeRecord> getRecord(String strChn) {
        Vector<StrokeRecord> recordvec = StrokeRecordLoader.loadFromContentProvider(m_ct.getContentResolver(), strChn);
        return  recordvec;
    }

    @Override
    public ShortPoint[] getChnGuide(String sChn, int nStrokeIndex) {
        // TODO Auto-generated method stub
        String sFile = null;
        try {
            //String sPath = m_ct.getFilesDir().getAbsolutePath();
            String sPath  = FileUtil.getireadckclocalstrokedatafolder(true);
            sFile = sPath + "/fill.db";
            if (!new File(sFile).exists()) {
                //copyAssetFiles("fill.db", sFile);
                return null;
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return null;
        }
        SQLiteDatabase db = SQLiteDatabase.openDatabase(sFile, null, SQLiteDatabase.OPEN_READONLY);
        if (db == null)
            return null;
        ShortPoint[] sp = null;
        String strSel = String.format("code='%s' AND idx=%d", sChn, nStrokeIndex);
        Cursor cur = db.query("tb_guide", new String[]{"data"}, strSel, null, "", "", "");
        if (cur != null) {
            sp = loadGuideData(cur);
            cur.close();
        }

        db.close();
        return sp;
    }

    private boolean copyAssetFiles(String sAsset, String sFile) throws Exception {
        InputStream is = m_ct.getAssets().open(sAsset);
        if (is == null)
            return false;
        int n = is.available();
        if (n <= 0) {
            is.close();
            return false;
        }
        byte[] bData = new byte[n];
        is.read(bData);
        is.close();
        FileOutputStream fos = new FileOutputStream(sFile);
        fos.write(bData);
        fos.close();
        return true;
    }

    static ShortPoint[] loadGuideData(Cursor cur) {
        if (!cur.moveToFirst())
            return null;
        int nSize;
        byte[] b = cur.getBlob(0);
        if ((b == null) || (nSize=b.length)<=0 || (nSize & 3)!=0)
            return null;
        return StrokeRecordLoader.loadShortPoint(b);
    }


    /**
     * dict 点击田字格 笔顺功能
     * @param sender
     * @param strStrokeName
     * @return
     */
    @Override
    public int OnFinishedListerner(Object sender, String strStrokeName) {
        int nwait = 0;
        if (!TextUtils.isEmpty(strStrokeName)) {
            String audiofilename = "";
            for (int i = 0 ; i < mStrokeNameTable.length; i++) {
                if (mStrokeNameTable[i].equals(strStrokeName)) {
                    audiofilename = String.valueOf(i) + ".ogg";
                }
            }

            if (!TextUtils.isEmpty(audiofilename)) {
                try {
                    AssetFileDescriptor fd = (AssetFileDescriptor)m_ct.getAssets().openFd("strokeogg/" + audiofilename);
                    if (fd != null) {
                        nwait = startStrokePlayer(fd);
                    };

                    if (nwait > 0) {
                        Thread.sleep(nwait);
                        nwait = 0;
                        nwait  = (nwait + 99)/100;
                    }
                    return nwait;
                } catch (Exception o) {

                }
            }


             //return PlayWave(strStrokeName);
        }

        if (mStrokeWave != null)
            mStrokeWave.closeWave();

        return nwait;
    }

    private int PlayWave(String strStrokeName) {
        if (mStrokeWave == null)
            mStrokeWave = new StrokeWave();
        return mStrokeWave.PlayWave(m_ct.getContentResolver(), strStrokeName, 0, false);
    }

    @Override
    public void OnClickView(Object sender) {
        setStrokeWord(mStrokeWord);
    }

    private int startStrokePlayer(AssetFileDescriptor fd) {

        int ret = 0;
        try {
            if(!createStrokePlayer()) {
                return 0;
            }
            mStrokePlayer.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
            fd.close();
            mStrokePlayer.prepare();
            ret = mStrokePlayer.getDuration();
            mStrokePlayer.start();
            return ret;
        } catch (IllegalArgumentException e) {
        } catch (IllegalStateException e) {
        } catch (IOException e) {
        }
        if(ret == 0) {
            onlyCloseStrokePlayer();
        }
        return ret;
    }



    private boolean createStrokePlayer() {
        mStrokePlayer = new MediaPlayer();
        mStrokePlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener(){
            @Override
            public void onPrepared(MediaPlayer mp) {
            }
        });

        mStrokePlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {

            }
        });

        mStrokePlayer.setOnErrorListener(new MediaPlayer.OnErrorListener(){
            @Override
            public boolean onError(MediaPlayer mp, int what, int extra) {
                onlyCloseStrokePlayer();
            return false;
        }
    });

        return (null != mStrokePlayer);
    }


    private synchronized void onlyCloseStrokePlayer() {
        try{
            try{
                if(null != mStrokePlayer) {
                    mStrokePlayer.stop();
                    mStrokePlayer.release();
                    mStrokePlayer = null;
                }
            }catch(Exception e){
            }
        }catch(Exception e){
        }
    }

    @Override
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        TLog.log("worddict onDetachedFromWindow");
        if (mDb != null) {
            mDb.close();
            mDb = null;
        }
        if (mEnDb != null) {
            mEnDb.close();
            mEnDb = null;
        }
    }

}
